yCheckbox
Description
The yCheckbox is an essential user interface element that allows users to make binary choices or toggle between two states. It's commonly used in forms, settings, and wherever a selection is needed. Usecases can be:
- disabling features or other components
- requesting consent for terms and conditions
- adjusting settings for an app
Basic Structure
The basic structure of yCheckbox includes a checkbox icon and an optional label that describes its purpose.
@note Image
Label
The label is an optional text placed next to the checkbox, providing information about the choice it represents. It can be positioned on either side of the checkbox, depending on the layout requirements.
Box
The box represents the clickable area of the yCheckbox, showing an indicator when selected. It can be customized in terms of color, size, and border to match the application's design theme.
Properties
Through its various properties the yCheckbox can be configured to suit your needs. The display below provides you with an overview of all the yCheckbox properties.
Properties can be changed directly through three methods:
- Inside the Toolbar, which is positioned in your workarea next to your component where you need it. It shows the most important properties, thus providing a fast and efficient way to configure your component in the most basic way.
- It may also occur in the Toolbar Extension, which is a seamless extension accesible as a dropdown item of the Toolbar. It extends the functionality of the Toolbar by providing advanced pickers for most used properties.
- Inside the Detail Panel, which is located in the righthand drawer. Every property of a component can be configured here.
- Generic
- Style
- Checkbox
- Links
- Events
METAread more
The identifier of the component that is unique within a page.
The type of the component. For this component it is -checkbox.
The custom name of the component. It serves for better identification of the component.
The custom version of the Checkbox-component. This can be used to ensure that all components work well together.
The CoreTheme, which will be apllied to the Checkbox. For further information on themes visit the themes page.
The subtheme subordinated to the previously specified CoreTheme, which will be apllied to the Checkbox. For further information on themes visit the themes page.
The group theme is a further variation of the subtheme which is specified especially for variations of a component inside the subtheme. For further information on themes visit the Theme-Manager page.
DISPLAYread more
This property specifies the display behavior of the component. This can be be set to:
- none
- block
- flex
- inline
This property specifies the type of positioning method used for the component. This can be be set to:
- static
- relative
- absolute
- sticky
- fixed
This property can toggle the visibility of the component. The two modes are completely hidden and fully shown.
SIZEread more
The minimum value for the width of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
The minimum value for the height of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
The value for the width of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- auto
The value for the height of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- auto
The maximum value for the width of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- none
The maximum value for the height of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- none
The flex property sets the length on flexible items. This sets the value in n-fold shares extrapolated to all other components with the flex display within the same container.
PLACEMENTread more
This property creates a space around the component, outside of the top border. This can be set in percent or pixels.
This property creates a space around the component, outside of the right border. This can be set in percent or pixels.
This property creates a space around the component, outside of the bottom border. This can be set in percent or pixels.
This property creates a space around the component, outside of the left border. This can be set in percent or pixels.
This property creates a space within the component, inside of the top border. This can be set in percent or pixels.
This property creates a space within the component, inside of the right border. This can be set in percent or pixels.
This property creates a space within the component, inside of the bottom border. This can be set in percent or pixels.
This property creates a space within the component, inside of the top border. This can be set in percent or pixels.
BACKGROUNDread more
The color of the background. This can be set as a color from a palette or a custom hex color.
BORDERread more
The color of the top border. This can be set as a color from a palette or a custom hex color.
The style of the top border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the top border. This can be set in percent or pixels.
The color of the right border. This can be set as a color from a palette or a custom hex color.
The style of the right border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the right border. This can be set in percent or pixels.
The color of the bottom border. This can be set as a color from a palette or a custom hex color.
The style of the bottom border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the bottom border. This can be set in percent or pixels.
The color of the left border. This can be set as a color from a palette or a custom hex color.
The style of the left border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the left border. This can be set in percent or pixels.
The radius of the corners of all the borders. This can be set in percent or pixels.
SHADOWread more
The shadow of the component. This is set by the 4 sub-properties x, y, blur and spread of the shadow-property, which can be further read about in the shadow-property section.
OPACITYread more
The opacity of all colored parts of the component. This value is set in percent.
LABELread more
The color of the label text. This can be set as a color from a palette or a custom hex color.
The font-family of the label text. This can be picked from a large list of provided fonts.
The font-weight of the label text. This can be set in a custom number, as example:
- 400 = normal(regular)
- 500 = medium
- 600 = semi bold
- 700 = bold
The font-style of the label text. This can be set to normal, italic or oblique.
The text-transformation of the label text. This can be set to:
- capitalize
- uppercase
- lowercase
- none
- full-width
The text-decoration of the label text. This can be set to:
- strikethrough
- underline
The font-size of the label text. This can be set in: -cm
- mm
- in
- px
- em
- ex
- ch
- rem
The actual written text in the label. There is no limit to the number of characters.
The actual written text in the left label. There is no limit to the number of characters.
BOXread more
The color of the turned off box background. This can be set as a color from a palette or a custom hex color.
The color of the border of the turned off box. This can be set as a color from a palette or a custom hex color.
The color of the turned on box background. This can be set as a color from a palette or a custom hex color.
The color of the border of the turned on box. This can be set as a color from a palette or a custom hex color.
The color of the icon inside the turned on box. This can be set as a color from a palette or a custom hex color.
The value for the width of the border of box. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- auto
The style of the border of the box. This can be be set to:
- solid
- dotted
- dashed
- none
The color of the circle-animation of the box. This can be set as a color from a palette or a custom hex color.
The opacity of the colored circle animation of the box. This value is set in percent.
The size of the circle animation of the box. This value is set in px.
The value to be displayed inside the box.
STATEread more
This property can disable or enable the disabled-state of the Checkbox-component.
This property can disable or enable the error-state of the Checkbox-component.
TOOLTIPread more
The text of the tooltip, which is displayed when hovering over the Checkbox-component. If you do not insert anything, no tooltip appears.
ERRORread more
The message to be displayed, if an error occurs.
VALUEread more
This property defines a link to another component by specifying the componentId or componentName, Page, Component, ID, Event. The data from the link will represent true or false.
Usage
In this section you'll find a collection of application scenarios and examples that illustrate how to leverage the yCheckbox in ways that deviate from its standard behavior, as defined by yBase. This section aims to inspire and guide you through various possibilities, helping you to implement more complex or unique functionalities tailored to your specific needs. General properties that are universally applicable can be found in the yBase usage section.
Variations
- Elevated
- Flat
- Outlined
- Rounded
- Plain
Custom Style Variations
Configure your yCheckbox with unique styles to emphasize their importance or to better integrate with your application's design.
- Standard
- Dark Mode
Setting the Checkbox Value
The yCheckbox component's value can be dynamically assigned either programmatically via JavaScript or by establishing a link to another component's value—known as a SourceLink. This flexibility allows the yCheckbox to respond to user interactions or application states in real time.
Via JavaScript
To set the yCheckbox's value using JavaScript, access the value property within the "style" > "thumb" category. This method is ideal for changing the yCheckbox's state based on user interactions or other events within your application.
Here’s how you can set the value in JavaScript:
// function onCheckbox_1_EvtClicked (apiObject, component, eventData) {
var desiredValue = true; // or false
component.set("style", "thumb", "value", desiredValue);
// }
Simply replace desiredValue with the appropriate boolean or comparable value that corresponds to the yCheckbox's position.
Via SourceLink Picker
To link the yCheckbox’s value with another component (e.g. another yCheckbox), use the SourceLink Picker. This feature binds the yCheckbox’s state to another component's value, allowing for integrated component behavior.
How to:
- Create another yCheckbox component in your application.
- Select the created yCheckbox and open the Detail Panel.
- Within these settings, proceed to the "Links" section and open "value".
- Create a new SourceLink -> select the other yCheckbox you just created and choose "value" as an event.
Now each time you trigger the second yCheckbox, the first one will also be triggered. To make this both ways you have to repeat this process for the other yCheckbox as well.
Alternatively you can use the SourceLink Picker in the Toolbar as a Toolbar Extension.
Setting Error States
Use the yCheckbox to provide immediate feedback on form validations by setting an error state.
// Example: Validate Checkbox State
// function onButton_1_EvtClicked (apiObject, component, eventData) {
leet checkboxComponent = apiObject.ui.getObject(checkboxId);
const isChecked = checkboxComponent.get("style", "box", "value");
if (!isChecked) {
// Set error state and message
checkboxComponent.set("component", "error", "error", true);
checkboxComponent.set("component", "error", "errorMessage", "This field is required.");
} else {
// Clear error state
checkboxComponent.set("component", "error", "error", false);
}
//}
Integration with Other Components
The yCheckbox can interact with other components, enabling or disabling functionalities based on its state. This behavior is essential for creating dynamic forms and interfaces.
// Example: Toggle visibility of another component based on checkbox state
// function onCheckbox_1_EvtClicked (apiObject, component, eventData) {
const isChecked = eventData.data;
let targetComponentId = 2;
let targetComponentType = "y-input";
const targetComponent = apiObject.ui.getObject(
targetComponentId,
targetComponentType
);
if (isChecked) {
targetComponent.set("generic", "display", "visible", "visible");
} else {
targetComponent.set("generic", "display", "visible", "hidden");
}
//}